package logic

import (
	"context"
	"home-mgr/model"

	"home-mgr/homerpc/homerpc"
	"home-mgr/homerpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHouseAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseAddLogic {
	return &HouseAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *HouseAddLogic) HouseAdd(in *homerpc.HouseAddRequest) (*homerpc.HouseAddResponse, error) {
	// todo: add your logic here and delete this line

	home := model.House{

		UserId:  int(in.UserId),
		Title:   in.Title,
		Content: in.Content,
		Price:   float64(in.Price),
		Address: in.Address,
	}
	model.DB.Debug().Create(&home)
	return &homerpc.HouseAddResponse{
		HouseId: int64(home.ID),
	}, nil
}
